package com.xiaoqing.framework.support.autoconfigure;

import com.baomidou.mybatisplus.core.parser.ISqlParser;
import com.baomidou.mybatisplus.extension.parsers.BlockAttackSqlParser;
import com.baomidou.mybatisplus.extension.plugins.OptimisticLockerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PerformanceInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;

/**
 * @NAME: {@link }
 * @author: <a href="get_xiaobo@163.com">Josh_Xu</a>
 * @create: 2019-10-09 14:43
 **/
@Configuration
@MapperScan({"com.xiaoqing.framework.api"})
public class MybatisMapperAutoConfiguration {

    @Bean
    public PerformanceInterceptor performanceInterceptor(){
        return new PerformanceInterceptor();
    }

    @Bean
    public PaginationInterceptor paginationInterceptor(){
        PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
        ArrayList<ISqlParser> sqlParserArrayList = new ArrayList<>();
        sqlParserArrayList.add(new BlockAttackSqlParser());
        paginationInterceptor.setSqlParserList(sqlParserArrayList);
        paginationInterceptor.setDialectType("mysql");
        return paginationInterceptor;
    }

    @Bean
    public OptimisticLockerInterceptor optimisticLockerInterceptor(){
        return new OptimisticLockerInterceptor();
    }
}
